import tkinter as tk
import time

def add_food(name):
    global last, food, today
    # 中药处理
    if name == '中药':
        end = time.time()
        # 默认两个小时
        sub = last + 7200 - end
        if sub > 0:
            food_label.config(text=f"{sub}秒钟之后再吃中药吧！")
    
    # 其它食物包括西药 
    if name!= "":
        if name in food and food[name] >= 0:
            # 增加一次
            today[name] = today.get(name, 0) + 1
            # 是否超量
            if today[name] > food[name]:
                food_label.config(text=f"不能再吃{name}了")
        

    # 记录最后一次时间
    last = time.time()
    print(name,last)

# 开始诊断
def send():
    # 步行，心跳，力量
    global step_entry, heart_entry, strength_entry
    try:
        v1 = int(step_entry.get())
        v2 = int(heart_entry.get())
        v3 = int(strength_entry.get())

        if v1 > 500 and v2 < 80 and v3 > 10:
            food_label.config(text="您已经康复了！")
        else:
            food_label.config(text="你还要继续努力哦！")
    except ValueError:
        food_label.config(text="请输入有效的数字！")

# 重置数据，全部归零
def reset():
    global food, today
    for d in food:
        today[d] = 0


root = tk.Tk()
root.title("术后康复机器人")

# 最后时间
last = 0
# 食物
food = {'中药':3,'羊肉': 0, '辣椒': 0, '海鲜': 0, '猪肉': 1, '烧烤': 1, '丹参丸': 1, '地高辛': 1, '米粥': 2}
# 今天数据
today = {}

food_label = tk.Label(root, text="患者饮食记录", font=("Arial", 14))
food_label.pack(pady=10)

food_var = tk.StringVar()
food_var.set("开始吃饭")
food_dropdown = tk.OptionMenu(root, food_var, *food.keys(), command=add_food)
food_dropdown.pack()

exercise_label = tk.Label(root, text="患者500米体测结果", font=("Arial", 14))
exercise_label.pack(pady=10)

reset_button = tk.Button(root, text="新的一天", command=reset)
reset_button.pack(side=tk.LEFT, padx=5)

step_entry = tk.Entry(root, width=10)
step_entry.pack(side=tk.LEFT, padx=5)
step_entry.insert(0,"200")
step_label = tk.Label(root, text="米")
step_label.pack(side=tk.LEFT)

heart_entry = tk.Entry(root, width=10)
heart_entry.pack(side=tk.LEFT, padx=5)
heart_entry.insert(0,"100")
heart_label = tk.Label(root, text="心跳(每分钟)")
heart_label.pack(side=tk.LEFT)

strength_entry = tk.Entry(root, width=10)
strength_entry.pack(side=tk.LEFT, padx=5)
strength_entry.insert(0,"5")
strength_label = tk.Label(root, text="力量(千克)")
strength_label.pack(side=tk.LEFT)

diagnose_button = tk.Button(root, text="诊断", command=send)
diagnose_button.pack(side=tk.LEFT, padx=5)

reset()

root.mainloop()